/*-------------------------------------------------------------------------
 - Copyright (c) 2024-2025 [XD-AMCC TEAM]
 - [XD-AMCC] is licensed under Mulan PSL v2.
 - You can use this software according to the terms and conditions of the Mulan PSL v2.
 - You may obtain a copy of Mulan PSL v2 at:
 -          http://license.coscl.org.cn/MulanPSL2
 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
 - OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 - TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 - See the Mulan PSL v2 for more details.
 ------------------------------------------------------------------------*/


/**
 * @brief  Recursive-Descent-Function of non-terminal statement.
 *
 * @author  WXQ#XDU
 * @date    2024.12
 */

#include "../_parser_inner.h"

#define THIS_NT_ID  statement

// statement                   //------------------ LL(2) production 31..36
//    :  selectionStatement
//    |  iterationStatement
//    |  jumpStatement
//    |  compoundStatement
//    |  labeledStatement
//    |  expressionStatement
//
t_tree_ptr RDF_statement (t_parser_ptr pThis) {
    int productionId = PRD_ID_UNKNOWN;
    t_tree_ptr root = tree_new_parent(THIS_NT, productionId);
    enter_nonterminal ( pThis, THIS_NT, root );
    CHECK_NULLTREE_ABORT ( root, root );
// -------  BEGIN of local action

    t_tree_ptr stmtNode = NULL;
    switch ( LOOK_AHEAD(pThis) ) {
        case TK_KW_IF:      productionId = 31;
            stmtNode = RDF_selectionStatement(pThis);
            break;
        case TK_KW_WHILE:   productionId = 32;
            stmtNode = RDF_iterationStatement (pThis);
            break;
        case TK_KW_GOTO :
        case TK_KW_BREAK :
        case TK_KW_CONTINUE:
        case TK_KW_RETURN : productionId = 33;
            stmtNode = RDF_jumpStatement (pThis);
            break;
        case TK_LBRACE:     productionId = 34;
            stmtNode = RDF_compoundStatement (pThis);
            break;
        case TK_ID:
            if ( TK_COLON == LOOK_AHEAD_K(pThis, 2) ) {
                productionId = 35;
                stmtNode = RDF_labeledStatement (pThis);
                break;
            }
            //// no break;  /* LA(2) != ':', this is a exprStmt */
        default:
            productionId = 36;
            stmtNode = RDF_expressionStatement (pThis);
            break;
    }

    CHECK_NULLTREE_ABORT ( stmtNode, root );
    tree_add_child(root, stmtNode);

// -------  END of local action
    if (PRD_ID_UNKNOWN == productionId) {
        ERROR_REPORT_BUG("Forgot to correct the value of "
                         "productionId in RDF_" NT_TEXT "()");
    }
    tree_reset_production( root, productionId );

LABEL_EXIT_RDF:
    exit_nonterminal  ( pThis, THIS_NT, root );
    return root;
}

